package cn.bb.entity;

import cn.bb.util.OutOfStockException;
import org.springframework.stereotype.Component;

@Component("phoneBiz")
public class PhoneBizImpl implements PhoneBiz {
    int num;
    @Override
    public void buyPhone(int num) {//
        System.out.println("手机的进货量"+num+"部");
        this.num = num;
    }

    @Override
    public void salePhone(int num) throws OutOfStockException {//
        System.out.println(this.num+"."+num);
        if(this.num < num){
            System.out.println("库存不足");
            //异常必须抛出
            throw new OutOfStockException("库存不足，客户需要"+num+"部库存只有："+this.num);
        }
        System.out.println("手机的销售量"+num+"部");
    }
}
